home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / g-io.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  96 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                              G N A T . I O                               --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. package body Gnat.IO is
  27.  
  28.    procedure Get (X : out Integer) is
  29.       function Getint return Integer;
  30.       pragma Interface (C, Getint);
  31.       pragma Interface_Name (Getint, "get_int");
  32.    begin
  33.       X := Getint;
  34.    end Get;
  35.  
  36.    procedure Put (X : Integer) is
  37.       procedure Putint (X : Integer);
  38.       pragma Interface (C, Putint);
  39.       pragma Interface_Name (Putint, "put_int");
  40.    begin
  41.       Putint (X);
  42.    end Put;
  43.  
  44.    procedure Get (C : out Character) is
  45.       function Getchar return Character;
  46.       pragma Interface (C, Getchar);
  47.    begin
  48.       C := Getchar;
  49.    end Get;
  50.  
  51.    procedure Put (C : Character) is
  52.       procedure Putchar (C : Character);
  53.       pragma Interface (C, Putchar);
  54.    begin
  55.       Putchar (C);
  56.    end Put;
  57.  
  58.    procedure Put (S : String) is
  59.    begin
  60.       for I in S'Range loop
  61.          Put (S (I));
  62.       end loop;
  63.    end Put;
  64.  
  65.    procedure Put_Line (S : String) is
  66.    begin
  67.       Put (S);
  68.       New_Line;
  69.    end Put_Line;
  70.  
  71.    procedure New_Line (Spacing : Positive := 1) is
  72.    begin
  73.       for I in 1 .. Spacing loop
  74.          Put (Ascii.LF);
  75.       end loop;
  76.    end New_Line;
  77.  
  78.    procedure Get_Line (Item : in out String; Last : out Natural) is
  79.       I_Length : Integer := Item'Length;
  80.       Nstore : Integer := 0;
  81.       C : Character;
  82.    begin
  83.       loop
  84.          Get (C);
  85.          exit when Nstore = I_Length;
  86.          if C = Ascii.Lf then
  87.             exit;
  88.          end if;
  89.          Item (Item'First + Nstore) := C;
  90.          Nstore := Nstore + 1;
  91.       end loop;
  92.       Last := Item'First + Nstore - 1;
  93.    end Get_Line;
  94.  
  95. end Gnat.IO;
  96.